package com.interest.modules.packagebranch.entity;

import com.interest.base.common.BuilderUtil;

/**
 * Created by yangfeng on 16-11-15.
 */
public class PackageStamp {
    private static final char JOINT_CHAR = '-';

    private String year;
    private String month;
    private String day;
    private String hour;
    private String minute;
    private String second;
    private String code;

    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }

    public String getMonth() {
        return month;
    }

    public void setMonth(String month) {
        this.month = month;
    }

    public String getDay() {
        return day;
    }

    public void setDay(String day) {
        this.day = day;
    }

    public String getHour() {
        return hour;
    }

    public void setHour(String hour) {
        this.hour = hour;
    }

    public String getMinute() {
        return minute;
    }

    public void setMinute(String minute) {
        this.minute = minute;
    }

    public String getSecond() {
        return second;
    }

    public void setSecond(String second) {
        this.second = second;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String toString() {
        return "" + year + JOINT_CHAR + month + JOINT_CHAR + day + JOINT_CHAR + hour
                + JOINT_CHAR + minute + JOINT_CHAR + second + JOINT_CHAR + code;
    }

    public static PackageStamp from(String text) {
        String[] stampSegments = BuilderUtil.getMinusSegments(text);
        if (null == stampSegments || stampSegments.length != 7) {
            return null;
        }

        PackageStamp stamp = new PackageStamp();
        stamp.setYear(stampSegments[0]);
        stamp.setMonth(stampSegments[1]);
        stamp.setDay(stampSegments[2]);
        stamp.setHour(stampSegments[3]);
        stamp.setMinute(stampSegments[4]);
        stamp.setSecond(stampSegments[5]);
        stamp.setCode(stampSegments[6]);

        return stamp;
    }
}
